<?php

	class enzyme{
	
		var $clientEdit;
		var $nameEdit;
		
		var $client;
		var $name;
		var $origin;
		var $test;
		var $date;
		
		function sendEnzymeDetails($clientEdit, $nameEdit, $client, $name, $origin, $date){
			$this->clientEdit = $clientEdit;
			$this->nameEdit = $nameEdit;
			$this->client = $client;
			$this->name = $name;
			$this->origin = $origin;
			$this->date = $date;
		}
		
		function search($search){

			$query = "SELECT * FROM enzyme WHERE client like '%" . $search . "%' or name like '%" . $search . "%' or origin like '%" . $search . "%' or testProcedure like '%" . $search . "%' or dateSubmitted like '%" . $search . "%'";
			$user="root";
			$password="";
			$database="eais";
			$link = mysql_connect('localhost', 'root', '');
			mysql_select_db('eais', $link);
			$result = mysql_query($query);
			$size = mysql_num_rows($result);			
			if($size>0){			
				echo "<table id=\"myTable\">";
				echo "<thead>";
				echo "<tr>"; 
				echo "	<th>Client</th>"; 
				echo "	<th>Name</th>"; 
				echo "	<th>Origin</th>"; 
				echo "	<th>Test Procedure</th>"; 
				echo "	<th>Date Submitted</th>"; 
				echo "</tr>"; 
				echo "</thead>"; 

				echo "<tbody>"; 
				while($rows = mysql_fetch_assoc($result)){
				echo "	<tr>"; 
				echo "		<td>".$rows['client']."</td>"; 
				echo "		<td>".$rows['name']."</td>"; 
				echo "		<td>".$rows['origin']."</td>"; 
				echo "		<td>".$rows['testProcedure']."</td>"; 
				echo "		<td>".$rows['dateSubmitted']."</td>"; 
				echo "	</tr>";
				}
				echo "</tbody>"; 
				echo "</table>"; 
			}
			else
				echo "No Data";
		}
		
		function retrieve(){
			$query = "SELECT client, name FROM enzyme ORDER BY client";
			$user="root";
			$password="";
			$database="eais";
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			$result = mysql_query($query);
			$size = mysql_num_rows($result);
			if($size>0){
				$count=0;		
								
				echo "<div id=\"lHead\">";
				echo "	<span id=\"listHeader\">ENZYMES</span>";
				echo "</div>";
						
				echo "<div id=\"lBody\">";				
				echo "	<table id=\"enzymeTable\" cellspacing='0' cellpadding='0'>";
							while($rows=mysql_fetch_assoc($result)){
				echo "			<tr>";
				if($count%2==0){
					echo "				<td id=\"inner1".$count."\" style=\"background-color:white;\"  onclick=\"selectEnzyme('".$rows['client']."','".$rows['name']."');\" onmouseover=\"highlight('".$count."');\" onmouseout=\"unhighlight('".$count."');\">";
					echo "					<div id=\"inner2\">".$rows['client']." - ".$rows['name']."</div>";
					echo "				</td>";
				}
				else{
					echo "				<td id=\"inner1".$count."\" style=\"background-color:#e7e7e7;\"  onclick=\"selectEnzyme('".$rows['client']."','".$rows['name']."');\" onmouseover=\"highlight('".$count."');\" onmouseout=\"unhighlight('".$count."');\">";
					echo "					 <div id=\"inner2\">".$rows['client']." - ".$rows['name']."</div>";
					echo "				</td>";
				}
				echo "			</tr>";
							$count++;
							}
				echo "	</table>";
				echo "</div>";
				
				echo "<div id=\"lLower\">";
				echo "</div>";

					if($from=="edit")
						echo "<center><input type=\"button\" value=\"Submit\" id=\"buttonSubmit\" onclick=\"submitEnzymeData();return false;\" /></center>";
			}
			else
				echo "No Data for Enzyme";
			echo "<input type=\"button\" id=\"addButton\" value=\"Add\" onclick=\"addEnzyme('add');\" />";
		}
		
		function viewInfo($client, $name){
			$query = "SELECT client, name, origin, testProcedure, dateSubmitted FROM enzyme WHERE client='$client' AND name='$name' ";
			$user="root";
			$password="";
			$database="eais";
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			$result = mysql_query($query);
			
			while($row = mysql_fetch_assoc($result)){
				$client = $row['client'];
				$name = $row['name'];
				$origin = $row['origin'];
				$date = $row['dateSubmitted'];
			}			
			echo "	<script>";
			
			echo "		client = \"".$client."\";";
			echo "		name = \"".$name."\";";
			echo "		origin = \"".$origin."\";";
			echo "		date = \"".$date."\";";
			
			echo "		from = \"view\";";

			echo "		$.post('viewEnzymeInfo.php',{";

			echo "			client: client,";
			echo "			name: name,";
			echo "			origin: origin,";
			echo "			date: date,";
			
			echo "			from:from";
			
			echo "			},function(data){";
			echo "				$('#view').html(data);";
			echo "			}";
			echo "		);";
			echo "	</script>";
		}
		
		function add(){
			$user="root";
			$password="";
			$database="eais";		
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			mysql_query("insert into enzyme(client, name, origin, dateSubmitted) values('$this->client', '$this->name', '$this->origin', '$this->date')");
		
			echo "You have successfuly added ".$this->name."<br />";
			echo "<input type='button' value='Add Enzyme' id='addAnother' onclick=\"showForm();return false;\">";
		}
				
		function retrieveInfo($company){
			$user="root";
			$password="";
			$database="eais";		
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			$result = mysql_query("SELECT name, origin, testProcedure, dateSubmitted FROM enzyme where name='$this->name' ");
		
			$rows=mysql_fetch_assoc($result);
			
			echo "<input type='hidden' name='client' value='".$name."' id='client' /><br />";
			echo "Name<br /><input type='text' name='company' value=\"".$rows['name']."\" id='company' /><br />";
			echo "Place of Origin<br /><input type='text' name='address' value=\"".$rows['origin']."\" id='address' /><br />";
			echo "Test Procedure<br /><input type='text' name='cellNo' value=\"".$rows['testProcedure']."\" id='cellNo' /><br />";
			echo "Date Submitted<br /><input type='text' name='telNo' value=\"".$rows['dateSubmitted']."\" id='telNo' /><br />";
			echo "<input type='button' value='Submit' id='buttonSubmit' onclick=\"editClientData('editSelectedClient');return false;\" />";
			echo "<input type='button' value='Cancel' id='buttonCancel' onclick='cancel();return false;' />";
		}
		
		function edit(){
			$user="root";
			$password="";
			$database="eais";
			$link = mysql_connect('localhost', $user, $password);
			mysql_select_db($database,$link);
			mysql_query("UPDATE enzyme SET client = '$this->client', name = '$this->name', origin = '$this->origin', dateSubmitted = '$this->date' WHERE client = '$this->clientEdit' AND name = '$this->nameEdit' ");
			
			echo "<br />You have successfuly edited it<br />";
		}
		
		function set_company($new_company) {
			$this->company = $new_company;
		}
		
		function set_address($new_address) {
			$this->company = $new_address;
		}
		
		function set_cellNo($new_cellNo) {
			$this->company = $new_cellNo;
		}
		
		function set_telNo($new_telNo) {
			$this->company = $new_telNo;
		}
		
		function set_faxNo($new_faxNo) {
			$this->company = $new_faxNo;
		}
		
		function set_emailAdd($new_emailAdd) {
			$this->company = $new_emailAdd;
		}

		function get_company() {
			return $this->company;
		}
		
		function get_address() {
			return $this->address;
		}
}